/** 
 * Copyright (C), 2010-2012, AIYOU Software Co.,Ltd. ALL RIGHTS RESERVED. 
 * File name:SysLogServiceImp.java
 * Version:1.0
 * Date:Dec 6, 2011
 * Description: 
 * author:zhijian.zhang
 */
package com.tietiao.service.syslog;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.tietiao.common.bean.ThreadLocalBean;
import com.tietiao.common.constants.SystemContext;
import com.tietiao.dao.SysLogMapper;
import com.tietiao.dao.model.SysLog;
@Service
public class SysLogServiceImp implements SysLogService {
	@Resource
	private SysLogMapper sysLogMapper;
	/* (non-Javadoc)
	 * @see com.tietiao.service.syslog.SysLogService#createSysLog(com.tietiao.dao.model.SysLog)
	 */
	@Override
	public int insertSysLog(SysLog sysLog) {
		return sysLogMapper.insert(sysLog);
	}
	/* (non-Javadoc)
	 * @see com.tietiao.service.syslog.SysLogService#insertSysLog(java.lang.String, java.lang.String)
	 */
	@Override
	public int insertSysLog(int opType,String modele, String description) {
		SysLog sysLog = new SysLog();
		sysLog.setOpType(opType);
		sysLog.setOpTime(new Date());
		sysLog.setOpModule(modele);
		sysLog.setOpDescription(description=description==null?" ":description);
		ThreadLocalBean bean = SystemContext.getThreadLocalBean();
		if(bean!=null){
			sysLog.setUserId(bean.getSysUser().getUserId());
			sysLog.setOpIp(bean.getUserIp());
		}else{
			sysLog.setUserId(1);
			sysLog.setOpIp("--");
		}
		return insertSysLog(sysLog);
	}

}
